package com.sloan.community.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @Author: yaosj
 * @CreateTime: 2024-12-17
 */
public class NumberUtils {

    public static String formatNumber(BigDecimal number) {
        if (number == null) {
            return "0";
        }
        BigDecimal val = new BigDecimal("10000.00");
        if (number.compareTo(val) >= 0) {
            // 当数字大于或等于10000时，转化为以“万”表示
            BigDecimal result = number.divide(val, 2, RoundingMode.HALF_UP);
            return result + "w";
        } else {
            return number.setScale(0, RoundingMode.HALF_UP).toString();
        }
    }
}
